package cn.yx.common.security.webflux.handler;

import cn.yx.common.core.pojo.ResponseVo;
import cn.yx.common.webflux.util.WebFluxUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * <p>访问权限不足处理器（未授权处理器）</p>
 *
 * @author Wgssmart
 */
@Component
public class CustomAccessDeniedHandler implements ServerAccessDeniedHandler {

    @Override
    public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException denied) {
        return WebFluxUtil.write(exchange.getResponse(), ResponseVo.authorizationError());
    }

}
